#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Módulos 
import sys, gtk, pygame, utils, objetos
from pygame.locals import *

# Constantes

# Clases
# ---------------------------------------------------------------------
        
class Linea:
	def __init__(self,texto,posx,posy):
		self.text,self.rect = utils.textotls(texto, posx,posy,14,(0,0,0))


class Lamparita(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.sonido = pygame.mixer.Sound("sounds/eureka.ogg")
        self.image = utils.load_image("images/lamparita_chica.png", True)
        self.rect = self.image.get_rect()
        self.rect.centerx = 80*utils.RES
        self.rect.centery = 300*utils.RES
        self.sonido.set_volume(0.1)   
        self.flag_sonido = True


# ---------------------------------------------------------------------
def dibujar(screen,cursor_picture, clock):
    salir = 0
    background_image = utils.load_image('images/fondo_4.jpg')
    btn_adelante = objetos.BotonAdelante()
    btn_atras = objetos.BotonAtras()
    
    
    clase, clase_rect = utils.texto_clase("Clase 4", 740*utils.RES, 30*utils.RES)
           
    titulo, titulo_rect = utils.texto_titulo("QUIEN HACE QUE? LOS ACTORES SOCIALES", 270*utils.RES, 60*utils.RES)
    
    lamparita = Lamparita()
    dialog = utils.load_image('images/c4_1c.png', True)
    frame = 0
    show_dialog = False
    fondo = utils.load_image('images/c4_1a.jpg')
    
    while salir == 0:
    
    	# Pump GTK messages.sub
		while gtk.events_pending():
			gtk.main_iteration()
			
		for eventos in pygame.event.get():
			if eventos.type == QUIT:
				sys.exit(0)
			elif eventos.type == pygame.VIDEORESIZE:
			   pygame.display.set_mode(eventos.size, pygame.RESIZABLE)	
			elif eventos.type == MOUSEBUTTONDOWN:
				if btn_adelante.rect.collidepoint(pygame.mouse.get_pos()):
					salir = 2
					btn_adelante.sonido.play()	
				elif btn_atras.rect.collidepoint(pygame.mouse.get_pos()):
					salir = -1					
					btn_atras.sonido.play()	
				elif lamparita.rect.collidepoint(pygame.mouse.get_pos()):
					#print ("sonido play")
					lamparita.sonido.play()	
					if show_dialog == False:
						show_dialog = True
					else:
						show_dialog = False	

		# Realiza la animacion del texto
		
		
		screen.blit(background_image, (0, 0))
		screen.blit(fondo, (170*utils.RES, 80*utils.RES))
		screen.blit(clase, clase_rect)
		screen.blit(titulo, titulo_rect)
		screen.blit(lamparita.image, lamparita.rect)
		if frame > 80:
			if lamparita.flag_sonido:
				lamparita.sonido.play()	
				lamparita.flag_sonido = False
		if show_dialog == True:
			screen.blit(dialog, (int(50*utils.RES), int(250*utils.RES)))		
		screen.blit(btn_adelante.image, btn_adelante.rect)
		screen.blit(btn_atras.image, btn_atras.rect)
		screen.blit(cursor_picture, pygame.mouse.get_pos())
		pygame.display.flip()

		# Try to stay at 30 FPS
		clock.tick(30)
		frame = frame + 1
                	 
    return salir

# This function is called when the game is run directly from the command line:
# ./TestGame.py 
def main():
	
	pygame.init()
	screen = pygame.display.set_mode((int(800*utils.RES), int(520*utils.RES)), pygame.RESIZABLE) #pygame.display.get_surface() #

	# Fake a Sugar cursor for the pyGame canvas area
	pygame.mouse.set_cursor((8,8),(0,0),(0,0,0,0,0,0,0,0),(0,0,0,0,0,0,0,0))
	cursor_picture = pygame.image.load('images/standardcursor.png')
	cursor_picture.convert_alpha() 
	clock = pygame.time.Clock()
	dibujar(screen,cursor_picture,clock)

if __name__ == '__main__':
   main()
